package com.cn.aam.checaiduo.ui.homepage.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.VirtualLayoutManager.LayoutParams;
import com.cn.aam.checaiduo.R;
import com.cn.aam.checaiduo.ui.homepage.MainActivity;
import com.cn.aam.checaiduo.ui.me.BeginnerParkActivity;
import com.cn.aam.checaiduo.utils.MyViewsUtils;

import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.cn.aam.checaiduo.Const.INTENT_REQUEST_PARK;

/**
 * monker on 2017/5/23.
 */

public class HomeFloatButtonAdapter extends DelegateAdapter.Adapter<HomeFloatButtonAdapter.MainViewHolder> {

    private Context mContext;
    private LayoutHelper mLayoutHelper;
    private LayoutParams mLayoutParams;
    private int mCount = 0;


    public HomeFloatButtonAdapter(Context context, LayoutHelper layoutHelper, int count) {
        this(context, layoutHelper, count, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300));
    }

    public HomeFloatButtonAdapter(Context context, LayoutHelper layoutHelper, int count, @NonNull LayoutParams layoutParams) {
        this.mContext = context;
        this.mLayoutHelper = layoutHelper;
        this.mCount = count;
        this.mLayoutParams = layoutParams;
    }


    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mLayoutHelper;
    }

    @Override
    public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(mContext).inflate(R.layout.list_vitem_homemain_float, parent, false);
        return new MainViewHolder(v);
    }

    @Override
    public void onBindViewHolder(MainViewHolder holder, int position) {
        holder.itemView.setLayoutParams(new LayoutParams(mLayoutParams));
    }


    @Override
    protected void onBindViewHolderWithOffset(MainViewHolder holder, int position, int offsetTotal) {
    }


    @Override
    public int getItemCount() {
        return mCount;
    }


    public class MainViewHolder extends RecyclerView.ViewHolder {


        public MainViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        protected void finalize() throws Throwable {
            super.finalize();
        }

        @OnClick()
        void clickFloatButton() {
            if (MyViewsUtils.isFastDoubleClick()) return;
            ((MainActivity) mContext).startActivityForResult(BeginnerParkActivity.newInstance(mContext), INTENT_REQUEST_PARK);
        }
    }
}
